package server.mapper;

import server.HttpServlet;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xingyi
 */
public class Mapper {
    private Map<String, Host> hostMap = new HashMap<>();

    public void addHost(Host host) {
        hostMap.put(host.getName(), host);
    }

    public HttpServlet getServlet(String hostName, String url) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Host host = hostMap.get(hostName);
        if (host == null) {
            return null;
        }
        return host.getServlet(url);
    }
}
